<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head >
	<th:block th:include="include :: header" />
	<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-inventoryInfo-edit" th:object="${inventoryInfo}">
            <input id="inventoryId" name="inventoryId" th:field="*{inventoryId}"  type="hidden">
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">物品名称：</label>
						<div class="col-sm-8">
							<input id="itemName" name="itemName" th:field="*{itemName}" class="form-control" type="text" required>
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">入库单号：</label>
						<div class="col-sm-8">
							<input id="orderNo" name="orderNo" th:field="*{orderNo}" class="form-control" th:value="${orderNo}" type="text" readonly>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">入库日期：</label>
						<div class="col-sm-8">
							<div class="input-group date">
								<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input id="storageTime" name="storageTime" th:field="*{storageTime}" type="text" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" required>
							</div>
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">经办人：</label>
						<div class="col-sm-8">
							<input id="itemAgent" name="itemAgent" th:field="*{itemAgent}" class="form-control"type="text" readonly>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">总库存：</label>
						<div class="col-sm-8">
							<input id="itemNum" name="itemNum" th:field="*{itemNum}"  class="form-control" type="text" readonly>
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">总金额：</label>
						<div class="col-sm-8">
							<input id="itemSum" name="itemSum" th:field="*{itemSum}"  class="form-control" type="text" readonly>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-12">
					<div class="form-group">
						<label class="col-xs-2 control-label">备注：</label>
						<div class="col-xs-10">
							<textarea id="remark" name="remark" th:field="*{remark}" maxlength="500" class="form-control" rows="5"></textarea>
						</div>
					</div>
				</div>
			</div>
			<!-- 商品列表 -->
			<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="addInventoryPrice()" shiro:hasPermission="business:inventoryPrice:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:inventoryPrice:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
			</div>

			<label class="col-xs-1 control-label"></label>
			<div class="col-xs-11">
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table" data-mobile-responsive="true"></table>
				</div>
			</div>
		</form>
    </div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
		//库存信息
		var prefix = ctx + "business/inventoryInfo";
		//商品信息
		var prefixPrice = ctx + "business/inventoryPrice";
		var editFlag = "";
		var removeFlag = "";
		$("#form-inventoryInfo-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

		$(function() {
			var options = {
				url: prefixPrice + "/list?inventoryId="+[[${inventoryId}]],
				createUrl: prefixPrice + "/add",
				updateUrl: prefixPrice + "/edit/{id}",
				removeUrl: prefixPrice + "/remove",
				exportUrl: prefixPrice + "/export",
				modalName: "商品规格",
				search: false,
				showExport: true,
				columns: [{
					checkbox: true
				},
					{
						field : 'inventoryPriceId',
						title : '规格中间表ID',
						visible: false
					},
					{
						title: "序号",
						formatter: function (value, row, index) {
							return $.table.serialNumber(index);
						}
					},
					{
						field : 'inventoryId',
						title : '库存ID',
						visible: false
					},
					{
						field : 'sizeName',
						title : '规格'
					},
					{
						field : 'priceName',
						title : '规格值'
					},
					{
						field : 'itemNum',
						title : '库存',
						sortable: true
					},
					{
						field : 'itemSum',
						title : '单价',
						sortable: true
					},
					{
						title: '操作',
						align: 'center',
						formatter: function(value, row, index) {
							var actions = [];
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.inventoryPriceId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.inventoryPriceId + '\')"><i class="fa fa-remove"></i>删除</a>');
							return actions.join('');
						}
					}]
			};
			$.table.init(options);
		});

		$(function () {
			/* 日期控件 */
			layui.use('laydate', function() {
				var laydate = layui.laydate;
				laydate.render({
					elem: '#storageTime',
					type: 'datetime'
				});
			});
		})

		function addInventoryPrice(){
			var inventoryId = $("#inventoryId").val()
			var url = prefixPrice + "/add/"+inventoryId;
			$.modal.open("添加库存规格", url);
		}

		function submitHandler() {
			if ($.validate.form()) {
				$.ajax({
					type: "post",
					url: prefix + "/edit",
					data: {
						"inventoryId":$("#inventoryId").val(),
						"itemName": $("#itemName").val(),
						"orderNo": $("#orderNo").val(),
						"storageTime" : $("#storageTime").val(),
						"itemAgent": $("#itemAgent").val(),
						"itemNum": $("#itemNum").val(),
						"itemSum": $("#itemSum").val(),
						"remark": $("#remark").val(),
					},
					success: function(r) {
						if (r.code === web_status.SUCCESS) {
							$.modal.msgReload("编辑成功！");
						}
					}
				});
			}
		}
	</script>
</body>
</html>
